module.exports = (app) => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const Question = app.model.define('Question', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    uuid: { type: STRING(36), unique: true },
    name: { type: STRING(255) },
    createdAt: { type: DATE, field: 'created_at' },
    updatedAt: { type: DATE, field: 'updated_at' },
  }, {
    tableName: 'questions'
  });

  Question.associate = () => {
    app.model.Question.belongsToMany(app.model.Conclusion, {
      through: app.model.MergeQuestionConclusion,
      foreignKey: 'fk_question',
      targetKey: 'id',
    });

    app.model.Question.hasMany(app.model.Answer, {
      foreignKey: 'fk_question',
      sourceKey: 'id',
    });
  };

  return Question;
};
